package com.qms.qep.controller;

import com.qms.common.core.controller.BaseController;
import com.qms.common.core.domain.AjaxResult;
import com.qms.common.annotation.Log;
import com.qms.common.enums.BusinessType;
import com.qms.qep.service.ISpcAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * SPC分析 控制器
 */
@RestController
@RequestMapping("/api/dataan/spc")
public class SpcAnalysisController extends BaseController {
    
    @Autowired
    private ISpcAnalysisService spcAnalysisService;
    
    /**
     * 获取过程能力分析数据
     */
    @PreAuthorize("@ss.hasPermi('dataan:spc:capability')")
    @GetMapping("/capability")
    public AjaxResult getCapabilityAnalysis(
            @RequestParam(required = false) String productId,
            @RequestParam(required = false) String processId,
            @RequestParam(required = false) String paramId,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {
        return AjaxResult.success(spcAnalysisService.getCapabilityAnalysis(productId, processId, paramId, startDate, endDate));
    }
    
    /**
     * 获取控制图数据
     */
    @PreAuthorize("@ss.hasPermi('dataan:spc:control-chart')")
    @GetMapping("/control-chart")
    public AjaxResult getControlChart(
            @RequestParam(required = false) String productId,
            @RequestParam(required = false) String processId,
            @RequestParam(required = false) String paramId,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "xbar-r") String chartType) {
        return AjaxResult.success(spcAnalysisService.getControlChart(productId, processId, paramId, startDate, endDate, chartType));
    }
    
    /**
     * 获取趋势分析数据
     */
    @PreAuthorize("@ss.hasPermi('dataan:spc:trend')")
    @GetMapping("/trend")
    public AjaxResult getTrendAnalysis(
            @RequestParam(required = false) String productId,
            @RequestParam(required = false) String processId,
            @RequestParam(required = false) String paramId,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate,
            @RequestParam(defaultValue = "false") Boolean predictNext) {
        return AjaxResult.success(spcAnalysisService.getTrendAnalysis(productId, processId, paramId, startDate, endDate, predictNext));
    }
    
    /**
     * 获取相关性分析数据
     */
    @PreAuthorize("@ss.hasPermi('dataan:spc:trend')")
    @GetMapping("/correlation")
    public AjaxResult getCorrelationAnalysis(
            @RequestParam String paramId1,
            @RequestParam String paramId2,
            @RequestParam(required = false) String productId,
            @RequestParam(required = false) String startDate,
            @RequestParam(required = false) String endDate) {
        return AjaxResult.success(spcAnalysisService.getCorrelationAnalysis(paramId1, paramId2, productId, startDate, endDate));
    }
} 